package com.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pojo.Dep;
import com.service.DepServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.vo.ResponseBean;

@RestController
@RequestMapping("/api")
@CrossOrigin("*")
public class DepController {

    @Autowired
    private DepServiceImpl depService;

    @RequestMapping("/searchDep")
    public ResponseBean searchDep(@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10") int limit,Integer depId,String depName){
        IPage result=depService.searchDep(page,limit,depId,depName);
        return new ResponseBean(0,result.getTotal(),result.getRecords());
    }

    @RequestMapping("/addDep")
    public ResponseBean addDep(Dep dep){
        int n=depService.addDep(dep);
        if (n>0){
            return new ResponseBean(200,0,"新增成功");
        }else{
            return new ResponseBean(500,0,"新增失败！");
        }
    }


}
